1from obspy import read
2import numpy as np
3
4files = ["fdsnws-1.mseed","fdsnws-2.mseed","fdsnws-4.mseed","fdsnws-5.mseed"]
5
6p_wave_arrival = 61.389 # first one only
7s_wave_arrival = 77.2
8s_wave_finished = 104.3
9
10sample_rate = 100 # Hz
11
12p_wave_buffer = []
13s_wave_buffer = []
14
15for file in files:
16 st = read(file)
17 print(st[0])
18
19 for sample_i in range(len(st[0])):
20 if sample_i >= p_wave_arrival*sample_rate and sample_i < s_wave_arrival*sample_rate:
21 p_wave_buffer.append(st[0][sample_i])
22 if sample_i >= s_wave_arrival*sample_rate and sample_i < s_wave_finished*sample_rate:
23 s_wave_buffer.append(st[0][sample_i])
24
25 st[0].write(f'{file}.wav', format='WAV', framerate=100)
26 np.array(st[0], dtype=np.int32).tofile(f'{file}.bin')
27
28# Convert lists to numpy arrays and save as binary files
29p_wave_array = np.array(p_wave_buffer, dtype=np.int32)
30s_wave_array = np.array(s_wave_buffer, dtype=np.int32)
31
32p_wave_array.tofile('p_wave_sample.bin')
33s_wave_array.tofile('s_wave_sample.bin')